#ifndef __SERVER_H__
#define __SERVER_H__

#include <soar.h>

__BEGIN_DECLS

struct cnfg_info
{/*{{{*/
    unsigned int ipckey;
    char errlog_location[LONG_FILE_NM_SIZE+1];
    unsigned int server_port;
    unsigned int monitor_port;
    int threads;
    struct
    {
        struct _cnfg_svcnode
        {
            char name[NAME_SIZE+1];
            char addr[LONG_FILE_NM_SIZE+1];
            unsigned int mode;
        } *svcnode;
        int num;
    } _svcnode_;
};/*}}}*/
extern struct cnfg_info cnfg_info;

struct _svc_rec
{/*{{{*/
    char name[NAME_SIZE+1];
    int svr_idx;
    unsigned int call;
    struct rb_link link_svc;
    struct listp_link link_svr;
};/*}}}*/

struct stat_info
{/*{{{*/
    struct
    {/*{{{*/
        pthread_mutex_t lock;
        struct _worker_info
        {
            int conn_num;
            unsigned int client_count;
            unsigned int client_call;
        } *worker;
    }/*}}}*/
    _worker_;

#define SVR_MAX_NUM         50
    struct
    {/*{{{*/
        pthread_mutex_t lock;
        struct _svr_info
        {
            char name[NAME_SIZE];
            pid_t pid;
            struct listp_link svcs;
        } svrs[SVR_MAX_NUM];
        struct rb_tree svcs;
    }/*}}}*/
    _svr_;
};/*}}}*/
extern struct stat_info stat_info;

enum thrd_state { THRD_RUNNING, THRD_SHUTDOWN };
struct operate_info
{/*{{{*/
    struct
    {
        pthread_mutex_t lock;
        unsigned int quit;
        enum thrd_state state;
    }
    _listener_;

    struct
    {
        pthread_mutex_t lock;
        unsigned int quit;
        enum thrd_state *state;
    }
    _worker_;
};/*}}}*/
extern struct operate_info operate_info;

__END_DECLS

#endif
